#include<iostream>
#include<etcd/Client.hpp>
#include<etcd/KeepAlive.hpp>
#include<etcd/Response.hpp>
#include<etcd/Watcher.hpp>
#include<etcd/Value.hpp>
int main()
{
    std::string etcd_host = "http://127.0.0.1:2379";
    //实例化客户端对象
    etcd::Client client(etcd_host);
    //向etcd中增加用户数据并且获得异步结果对象
    auto resp = client.put("/service/user","127.0.0.1:8080").get();
    if(resp.is_ok()==false)
    {
        std::cout<<"新增数据失败"<<resp.error_message()<<std::endl;
        return -1;
    }
    // 创建一个存活3秒的租约
    auto keep_alive = client.leasekeepalive(3).get();
    // 获取租约ID
    auto lease_id = keep_alive->Lease();
    //增加一个有租约限制的数据，并获取异步结果对象
    auto resp2 = client.put("/service/user2","127.0.0.1:8081",lease_id).get();
    if(resp.is_ok()==false)
    {
        std::cout<<"新增数据失败"<<resp.error_message()<<std::endl;
        return -1;
    }
    std::this_thread::sleep_for(chrono::seconds(10));
};